package com.example.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.dao.CategoryAdminDao;
import com.example.entity.PageResult;
import com.example.entity.QueryPageBean;
import com.example.pojo.Goods;
import com.example.pojo.GoodsCategory;
import com.example.service.CategoryAdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = CategoryAdminService.class)
public class CategoryAdminServiceImpl implements CategoryAdminService {
    @Autowired
    private CategoryAdminDao categoryAdminDao;
    @Override
    public List<GoodsCategory> findall() {
        List<GoodsCategory> goodsCategoryList=categoryAdminDao.findall();
        return goodsCategoryList;
    }

    @Override
    public PageResult findpage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<GoodsCategory> page = categoryAdminDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(GoodsCategory goodsCategory) {
        categoryAdminDao.add(goodsCategory);
    }

    @Override
    public void deleteById(Integer id) {
        categoryAdminDao.delete(id);
    }

    @Override
    public void edit(GoodsCategory goodsCategory) {
        categoryAdminDao.edit(goodsCategory);
    }

    @Override
    public GoodsCategory findById(Integer id) {
        return categoryAdminDao.findById(id);
    }
}
